package com.jushu.storbox.database;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.database.Cursor;

import com.huawei.sharedrive.sdk.android.model.response.ADUser;

@Deprecated
public class EnterpriseAddressDao extends BaseDao implements IEnterpriseAddressDao {
	private final static String TABLE_NAME_ENTERPRISE_ADDRESS_LIST = "tb_enterprise_address_list";
	@Override
	public long getLastUpdateTime(String objectId)
	{
		return 0;
	}
	@Override
	public void updateLastUpdateTime(String objectId)
	{
		
	}
	@Override
	public List<ADUser> queryMailList(String keyText)
	{
		Cursor cursor= this.getDb().rawQuery("select * from tb_enterprise_address_list where "+IBaseDao.name+" like ?",new String[] { "%" + keyText + "%" });
		if(cursor != null && cursor.getCount()>0)
		{
			List<ADUser> adUserList = new ArrayList<ADUser>();
			while (cursor.moveToNext())
			{
				ADUser adUser = new ADUser();
				adUser.setDepartment(cursor.getString(1));
				adUser.setId(cursor.getLong(2));
				adUser.setDomain(cursor.getString(3));
				adUser.setEmail(cursor.getString(4));
				adUser.setLoginName(cursor.getString(5));
				adUser.setName(cursor.getString(6));
				adUser.setModifiedAt(Long.parseLong(cursor.getString(7)));
				adUser.setObjectSid(cursor.getString(8));
				adUser.setRegionId(cursor.getInt(9));
				adUser.setRecycleDays(cursor.getInt(10));
				adUser.setSpaceUsed(cursor.getLong(11));
				adUser.setStatus(cursor.getString(12));
				adUserList.add(adUser);
			}
			if(adUserList.size()>0)
			{
				return adUserList;
			}
			else
			{
				return null;
			}
		}
		else
		{
			return null;
		}
	}
	@Override
	public void dbInsertMailList(List<ADUser> mailList) throws Exception {
		for(int i=0; i<mailList.size(); i++)
		{
			ContentValues cv = new ContentValues();
			cv.put(IBaseDao.name,mailList.get(i).getName());
			cv.put(IBaseDao.department, mailList.get(i).getDepartment());
			cv.put(IBaseDao.user_modifiedAt,mailList.get(i).getModifiedAt());
			cv.put(IBaseDao.email, mailList.get(i).getEmail());
			cv.put(IBaseDao.user_id, mailList.get(i).getId());
			cv.put(IBaseDao.loginName,mailList.get(i).getLoginName());
			cv.put(IBaseDao.objectSid, mailList.get(i).getObjectSid());
			cv.put(IBaseDao.recycleDays, mailList.get(i).getRecycleDays());
			cv.put(IBaseDao.regionId,mailList.get(i).getRegionId());
			cv.put(IBaseDao.spaceQuota,mailList.get(i).getSpaceQuota());
			cv.put(IBaseDao.spaceUsed,mailList.get(i).getSpaceUsed());
			cv.put(IBaseDao.user_status,mailList.get(i).getStatus());
			getDb().insert(TABLE_NAME_ENTERPRISE_ADDRESS_LIST, null, cv);
		}
	}
}
